package com.cly.api.config;

import com.cly.common.util.ThreadLocalUtil;
import feign.Logger;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import feign.codec.Decoder;
import org.springframework.context.annotation.Bean;

public class DefaultFeignConfig {

    @Bean
    public Logger.Level feignLogLevel(){
        return Logger.Level.FULL;
    }

    @Bean
    public RequestInterceptor userInfoRequestInterceptor(){
        return new RequestInterceptor() {
            @Override
            public void apply(RequestTemplate template) {
                // 获取用户信息
                Long userId = ThreadLocalUtil.get();
                if(userId == null){
                    return;
                }
                template.header("user-info", userId.toString());
            }
        };

    }
}
